package org.jradweb.core.web;

import java.util.Map;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.log4j.Logger;
import org.jradweb.core.orm.GenericDao;
import org.jradweb.core.orm.HibernateModel;
import org.springframework.web.context.WebApplicationContext;

public class JContextListener implements ServletContextListener {

	private static final Logger log=Logger.getLogger(JContextListener.class);
	
	public void contextDestroyed(ServletContextEvent arg0) {
	
	}

	public void contextInitialized(ServletContextEvent sce) {
		
		WebApplicationContext wAppCtx=(WebApplicationContext)sce.getServletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
		Map<Class,GenericDao> modelAndDaoList=org.jradweb.core.orm.HibernateUtils.getModelAndDaoList(wAppCtx);
		
		HibernateModel.initialize(modelAndDaoList);
		
		log.info("All hibernate models initialized...");
	}

}
